package com.atguigu.oss.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @ClassName ConstantPropertiesUtils
 * @Description TODO
 * @Detail 该类用于全局加载一些配置常量，这样就可以在项目中使用到这些常量，而不需要每次都要@Value注解注入
 *              步骤：
 *                  1、编写一个常量类实现InitializingBean接口
 *                  2、实现InitializingBean接口的afterPropertiesSet()方法
 *                      该方法是SpringBoot加载完该类的属性之后执行
 * @Author MyPC
 * @Date 2020/6/21
 * @Version 1.0
 */
@Component
public class ConstantPropertiesUtils implements InitializingBean{
    @Value("${aliyun.oss.file.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.file.keyid}")
    private String keyId;

    @Value("${aliyun.oss.file.keysecret}")
    private String keySecret;

    @Value("${aliyun.oss.file.bucketname}")
    private String bucketName;

    public static String END_POINT;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;
    @Override
    public void afterPropertiesSet() throws Exception {
        END_POINT = endpoint;
        ACCESS_KEY_ID = keyId;
        ACCESS_KEY_SECRET = keySecret;
        BUCKET_NAME = bucketName;
    }
}
